package com.jxd.controller;

import com.jxd.model.Employee;
import com.jxd.model.User;
import com.jxd.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @PostMapping("/login")
    public Map<String, Object> login(@RequestBody User user) {
        return userService.loginService(user);
    }

    @PostMapping("/addUser")
    public Map<String, Object> addUser(@RequestBody User user) {
        HashMap<String, Object> res = new HashMap<>();
        user.setRole("2");
        boolean flag = userService.save(user);
        System.out.println(user.getId());
        if (flag) {
            res.put("uid", user.getId());
            res.put("code", "200");
            return res;
        } else {
            res.put("code", "500");
            return res;
        }
    }

    @RequestMapping("/delUser")
    public String delEmp(@RequestBody List<Integer> empnos) {
        boolean flag = userService.removeByIds(empnos);
        if (flag) {
            return "success";
        } else {
            return "error";
        }
    }
}
